package FileManager;
import Method.Conexcute;

import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
@WebServlet(urlPatterns = "/Addfile")
@MultipartConfig(location = "D:\\picture")// location改为本地的绝对路径
public class AddfileServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Part part=request.getPart("file");
        String fileName = part.getSubmittedFileName();
        part.write(fileName);
        String file=fileName;
        Conexcute conexcute=new Conexcute();
        if(conexcute.execute("insert into `file` (`fi_name`) values ('"+file+"');")){
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().println("数据添加成功");
            response.sendRedirect("FileManager/file.jsp");
        }
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
